package com.yan.demo;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author taoge
 * @Date 2024/8/12 9:50
 * @Description
 */
public class ThreadPoolDemo2 {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(100);
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "卖出了一张票");
               countDownLatch.countDown();
            }
        };

        for (int i = 0; i < 100; i++) {
            threadPool.submit(runnable);
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        threadPool.shutdown();
        System.out.println("票卖完了");

    }
}
